package com.ruoyi.web.controller.hospital;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hospital.domain.Hospitals;
import com.ruoyi.hospital.service.IHospitalsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 传染病知名医院Controller
 * 
 * @author ruoyi
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/hospital/hospitals")
public class HospitalsController extends BaseController
{
    @Autowired
    private IHospitalsService hospitalsService;

    /**
     * 查询传染病知名医院列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitals:list')")
    @GetMapping("/list")
    public TableDataInfo list(Hospitals hospitals)
    {
        startPage();
        List<Hospitals> list = hospitalsService.selectHospitalsList(hospitals);
        return getDataTable(list);
    }

    /**
     * 导出传染病知名医院列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitals:export')")
    @Log(title = "传染病知名医院", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hospitals hospitals)
    {
        List<Hospitals> list = hospitalsService.selectHospitalsList(hospitals);
        ExcelUtil<Hospitals> util = new ExcelUtil<Hospitals>(Hospitals.class);
        util.exportExcel(response, list, "传染病知名医院数据");
    }

    /**
     * 获取传染病知名医院详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitals:query')")
    @GetMapping(value = "/{hospitalId}")
    public AjaxResult getInfo(@PathVariable("hospitalId") Long hospitalId)
    {
        return AjaxResult.success(hospitalsService.selectHospitalsByHospitalId(hospitalId));
    }

    /**
     * 新增传染病知名医院
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitals:add')")
    @Log(title = "传染病知名医院", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hospitals hospitals)
    {
        return toAjax(hospitalsService.insertHospitals(hospitals));
    }

    /**
     * 修改传染病知名医院
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitals:edit')")
    @Log(title = "传染病知名医院", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hospitals hospitals)
    {
        return toAjax(hospitalsService.updateHospitals(hospitals));
    }

    /**
     * 删除传染病知名医院
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitals:remove')")
    @Log(title = "传染病知名医院", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hospitalIds}")
    public AjaxResult remove(@PathVariable Long[] hospitalIds)
    {
        return toAjax(hospitalsService.deleteHospitalsByHospitalIds(hospitalIds));
    }
}
